package com.etlmaster.util.vfs;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import org.apache.commons.vfs2.Capability;
import org.apache.commons.vfs2.FileName;
import org.apache.commons.vfs2.FileSystem;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider;
import org.apache.commons.vfs2.provider.URLFileNameParser;

/**
 * @author Larry
 * @copyright Larry@etlMaster
 * @since 2017-09-10
 */
public class HdfsFileProvider extends AbstractOriginatingFileProvider {
	static final Collection<Capability> capabilities = Collections.unmodifiableCollection(Arrays.asList(new Capability[] {
		Capability.CREATE, 
		Capability.DELETE, 
		Capability.RENAME,
		Capability.GET_TYPE, 
		Capability.LIST_CHILDREN,
		Capability.READ_CONTENT, 
		Capability.GET_LAST_MODIFIED,
		Capability.URI, 
		Capability.WRITE_CONTENT,
		Capability.APPEND_CONTENT, 
		Capability.RANDOM_ACCESS_READ ,
		Capability.SET_LAST_MODIFIED_FILE
	}));

	public HdfsFileProvider() {
		super.setFileNameParser(new URLFileNameParser(9000));
	}

	public Collection<Capability> getCapabilities() {
		return capabilities;
	}

	protected FileSystem doCreateFileSystem(FileName rootName, FileSystemOptions fileSystemOptions) throws FileSystemException {
		return new HdfsFileSystem(rootName, null, fileSystemOptions);
	}
}
